package net.xdclass.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MailServiceImpl implements MailService {

    @Autowired
    private JavaMailSender mailSender;


    @Value("${spring.mail.from}")
    private  String from;

    @Override
    public void sendMail(String to, String subject, String content) {


        //创建邮箱消息对象
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();

        //发送人
        simpleMailMessage.setFrom(from);
        System.out.println(from.toString());


        simpleMailMessage.setTo(to);

        simpleMailMessage.setSubject(subject);

        simpleMailMessage.setText(content);

        mailSender.send(simpleMailMessage);
        log.info("邮件发送成功"+simpleMailMessage);
    }
}
